<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title data-i18n="resources.title_loadSymbolLib"></title>
    <script type="text/javascript" exclude="iclient-classic" include="iclient8c-plot" src="../../dist/classic/include-classic.js"></script>
    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%
        }

        #map {
            position: absolute;
            width: 100%;
            height: 100%;
        }

        #toolbar {
            position: absolute;
            top: 50px;
            right: 10px;
            width: 300px;
            text-align: center;
            z-index: 100;
            border-radius: 4px;
        }

        .winContent {
            padding: 5px;
            overflow-y: auto;
            height: 220px;

        }

        .popupWindow {
            background: #FFF;
            z-index: 9999;
            display: block;
        }

        .winTitle {
            margin-left: 20px;
            font-size: 14px;
            font-weight: bold;
        }
    </style>
</head>
<body>
<div id="toolbar" class="panel panel-primary">
    <div class='panel-heading'>
        <h5 class='panel-title text-center' data-i18n="resources.title_loadSymbolLib"></h5></div>
    <div class='panel-body content'>
        <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_plot" onclick="plotSymbol()"/>&nbsp; &nbsp;
        <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_cancelMarker" onclick="PlottingDrawCancel()"/>&nbsp; &nbsp;
        <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_clear" onclick="PlottingClear()"/>
    </div>
    <div id="popupWin" class="popupWindow" style="display: block;top: 400px; height: 150px;">
        <div class='panel'>
            <div class='input-group'>
                <div class="winTitle">
                    <span class="title_left" data-i18n="resources.text_symbolLibInfo"></span>
                </div>
            </div>
        </div>
        <div id="symbolLibInfo" class="winContent" style="overflow-y:auto;height:250px;">
        </div>
    </div>
</div>
<div id="map"></div>
<script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
<script>
    var plottingLayer, plottingEdit, layer, drawGraphicObject, map, plotting, symbolLibManager;
    var host = window.isLocal ? window.server : "https://iserver.supermap.io";
    var mapurl = host + "/iserver/services/map-world/rest/maps/World";
    var serverUrl = host + "/iserver/services/plot-jingyong/rest/plot/";

    init();

    function init() {
        map = new SuperMap.Map("map", {
            controls: [
                new SuperMap.Control.ScaleLine(),
                new SuperMap.Control.Zoom(),
                new SuperMap.Control.Navigation({
                    dragPanOptions: {
                        enableKinetic: true
                    }
                })]
        });
        map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
        layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", mapurl, {
            transparent: true,
            cacheEnabled: true
        }, {maxResolution: "auto"});
        layer.events.on({"layerInitialized": addLayer});

        plottingLayer = new SuperMap.Layer.PlottingLayer("标绘图层", serverUrl);
        plottingLayer.style = {
            fillColor: "#66cccc",
            fillOpacity: 0.4,
            strokeColor: "#66cccc",
            strokeOpacity: 1,
            strokeWidth: 3,
            pointRadius: 6
        };

        // 绘制标号;
        drawGraphicObject = new SuperMap.Control.DrawFeature(plottingLayer, SuperMap.Handler.GraphicObject);

        //态势标绘编辑
        plottingEdit = new SuperMap.Control.PlottingEdit();

        //添加态势标绘控件
        map.addControls([plottingEdit, drawGraphicObject]);

        plotting = SuperMap.Plotting.getInstance(map, serverUrl);

        loadSymbolLib();
    }

    function addLayer() {
        map.addLayers([layer, plottingLayer]);
        map.setCenter(new SuperMap.LonLat(0, 0), 0);

        plottingEdit.activate();
    }

    function loadSymbolLib() {
        symbolLibManager = plotting.getSymbolLibManager();
        symbolLibManager.events.on({"initializeCompleted": showSymbolLibInfo});
        symbolLibManager.initializeAsync();
    }

    function showSymbolLibInfo(result) {
        document.all.symbolLibInfo.innerHTML = "";

        if (0 === result.length) {
            return;
        }

        var symbolLib = symbolLibManager.getSymbolLibByIndex(0);


        //获取选中的对象
        var container = document.getElementById("symbolLibInfo");
        var table = document.createElement("table");
        var body = document.createElement("tbody");
        table.setAttribute("border", "1");
        table.setAttribute("borderColor", "black");
        table.setAttribute("width", "100%");

        //标号库名称
        var tr_SymbolLibName = document.createElement("tr");

        var tdName_SymbolLibName = document.createElement("td");
        var textName_SymbolLibName = document.createTextNode(resources.text_symbolLibName);
        tdName_SymbolLibName.appendChild(textName_SymbolLibName);
        tr_SymbolLibName.appendChild(tdName_SymbolLibName);

        var tdValue_SymbolLibName = document.createElement("td");
        var textValue_SymbolLibName = document.createTextNode(symbolLib.getSymbolLibName());
        tdValue_SymbolLibName.appendChild(textValue_SymbolLibName);
        tr_SymbolLibName.appendChild(tdValue_SymbolLibName);

        body.appendChild(tr_SymbolLibName);

        //标号库ID
        var tr_SymbolLibID = document.createElement("tr");

        var tdName_SymbolLibID = document.createElement("td");
        var textName_SymbolLibID = document.createTextNode(resources.text_SymbolLibID);
        tdName_SymbolLibID.appendChild(textName_SymbolLibID);
        tr_SymbolLibID.appendChild(tdName_SymbolLibID);

        var tdValue_SymbolLibID = document.createElement("td");
        var textValue_SymbolLibID = document.createTextNode(symbolLib.getSymbolLibID());
        tdValue_SymbolLibID.appendChild(textValue_SymbolLibID);
        tr_SymbolLibID.appendChild(tdValue_SymbolLibID);

        body.appendChild(tr_SymbolLibID);

        //标号库标号个数
        var tr_SymbolCount = document.createElement("tr");

        var tdName_SymbolCount = document.createElement("td");
        var textName_SymbolCount = document.createTextNode(resources.text_symbolCounts);
        tdName_SymbolCount.appendChild(textName_SymbolCount);
        tr_SymbolCount.appendChild(tdName_SymbolCount);

        var tdValue_SymbolCount = document.createElement("td");
        var textValue_SymbolCount = document.createTextNode(symbolLib.getSymbolCount());
        tdValue_SymbolCount.appendChild(textValue_SymbolCount);
        tr_SymbolCount.appendChild(tdValue_SymbolCount);

        body.appendChild(tr_SymbolCount);


        table.appendChild(body);
        container.appendChild(table);
    }

    function plotSymbol() {
        var symbolLib = symbolLibManager.getSymbolLibByIndex(0);
        if (null === symbolLib) {
            drawGraphicObject.deactivate();
            return;
        }

        drawGraphicObject.handler.libID = symbolLib.getSymbolLibID();
        drawGraphicObject.handler.symbolCode = getFirstSymbol();
        drawGraphicObject.handler.serverUrl = serverUrl;

        drawGraphicObject.deactivate();
        drawGraphicObject.activate();
    }

    function getCode(symbolInfo) {
        var nCode = -1;
        while (symbolInfo.symbolNodeType === "SYMBOL_GROUP") {
            symbolInfo = symbolInfo.childNodes[0];
        }

        nCode = symbolInfo.symbolCode;

        return nCode;
    }

    function getFirstSymbol() {
        var nCode = -1;
        var symbolLib = symbolLibManager.getSymbolLibByIndex(0);
        if (null === symbolLib) {
            drawGraphicObject.deactivate();
            return nCode;
        }

        var rootSymbolInfo = symbolLib.getRootSymbolInfo();

        var i = 0;
        nCode = getCode(rootSymbolInfo.childNodes[i]);
        while (-1 === nCode) {
            i++;
            nCode = getCode(rootSymbolInfo.childNodes[i]);
        }

        return nCode;
    }

    function PlottingDrawCancel() {
        drawGraphicObject.deactivate();
        plottingEdit.deactivate();

        plottingEdit.activate();
    }

    //清空绘制
    function PlottingClear() {
        drawGraphicObject.deactivate();
        plottingEdit.deactivate();

        plottingLayer.removeAllFeatures();
    }

    document.onmouseup = function (evt) {
        var evt = evt || window.event;
        if (evt.button === 2) {
            PlottingDrawCancel();
            return false;
        }
        evt.stopPropagation();
    }
</script>

</body>
</html>